package com.ruoyi.project.mall.controller;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bootdo.PageUtils;
import com.ruoyi.common.utils.bootdo.Query;
import com.ruoyi.common.utils.bootdo.R;
import com.ruoyi.common.utils.bootdo.UuidUtil;
import com.ruoyi.project.mall.domain.MallShopBankDO;
import com.ruoyi.project.mall.service.MallShopBankService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 店铺银行表
 * 
 * @author long
 * @email 499626561@qq.com
 * @date 2020-12-25 10:18:47
 */
 
@Controller
@RequestMapping("/mall/mallShopBank")
public class MallShopBankController {
	@Autowired
	private MallShopBankService mallShopBankService;
	
	@GetMapping()
	@RequiresPermissions("mall:mallShopBank:mallShopBank")
	String MallShopBank(){
	    return "mall/mallShopBank/mallShopBank";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("mall:mallShopBank:mallShopBank")
	public PageUtils list(@RequestParam Map<String, Object> params){
	    params.put("delFlag","0");
	    params.put("sort","ca_at");
	    params.put("order","desc");
        //查询列表数据
        Query query = new Query(params);
	    if(params.containsKey("name")&& StringUtils.isNotBlank(params.get("name").toString())){
            List<MallShopBankDO> mallShopBankList = mallShopBankService.likeList(query);
            int total = mallShopBankService.likeListCount(query);
            PageUtils pageUtils = new PageUtils(mallShopBankList, total);
            return pageUtils;
		}

		List<MallShopBankDO> mallShopBankList = mallShopBankService.list(query);
		int total = mallShopBankService.count(query);
		PageUtils pageUtils = new PageUtils(mallShopBankList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("mall:mallShopBank:add")
	String add(){
	    return "mall/mallShopBank/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("mall:mallShopBank:edit")
	String edit(@PathVariable("id") String id,Model model){
		MallShopBankDO mallShopBank = mallShopBankService.get(id);
		model.addAttribute("mallShopBank", mallShopBank);
	    return "mall/mallShopBank/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("mall:mallShopBank:add")
	public R save(MallShopBankDO mallShopBank){
	    mallShopBank.setId(UuidUtil.get32UUID());
	    mallShopBank.setDelFlag(0);
	    mallShopBank.setCaAt(new Date());
		if(mallShopBankService.save(mallShopBank)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("mall:mallShopBank:edit")
	public R update( MallShopBankDO mallShopBank){
		mallShopBank.setUpAt(new Date());
		mallShopBankService.update(mallShopBank);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("mall:mallShopBank:remove")
	public R remove( String id){
		MallShopBankDO mallShopBank = mallShopBankService.get(id);
		mallShopBank.setDelFlag(1);
		mallShopBank.setUpAt(new Date());
		if(mallShopBankService.update(mallShopBank)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("mall:mallShopBank:batchRemove")
	public R remove(@RequestParam("ids[]") String[] ids){
	   if(ids.length>0){
			for (String string : ids) {
				MallShopBankDO mallShopBank = mallShopBankService.get(string);
				mallShopBank.setDelFlag(1);
				mallShopBank.setUpAt(new Date());
				mallShopBankService.update(mallShopBank);
			}
		}
	
		return R.ok();
	}
	
}
